package com.jinyi.wwdeng.ui.permission

import android.Manifest
import com.jinyi.wwdeng.App
import com.jinyi.wwdeng.R
import org.json.JSONObject

/**
 * JinYiTest
 * @Author wwdeng
 * @CreateTime: 2024/4/16 17:04
 * @Annotation：权限配置
 */
object PermissionConfig {

    /**
     * 根据权限类型匹配对应的图标
     */
    fun getPermissionIcon(permission: String): Int{
        var resId = R.mipmap.pic_kind_tips_icon
        when(permission){
            Manifest.permission.READ_SMS -> {
                resId = R.mipmap.pic_permission_sms_icon
            }
            Manifest.permission.READ_CALL_LOG -> {
                resId = R.mipmap.pic_permission_call_icon
            }
            Manifest.permission.READ_PHONE_STATE -> {
                resId = R.mipmap.pic_permission_phone_status_icon
            }
            App.instance().getString(R.string.permission_app_list_data_collection) -> {
                resId = R.mipmap.pic_permission_app_list_icon
            }
        }
        return resId
    }

    /**
     * 根据权限类型匹配对应的名称
     */
    fun getPermissionTitle(permission: String): String{
        var title = ""
        when(permission){
            Manifest.permission.READ_SMS -> {
                title = App.instance().getString(R.string.permission_sms_data_collection)
            }
            Manifest.permission.READ_CALL_LOG -> {
                title = App.instance().getString(R.string.permission_call_log_collection)
            }
            Manifest.permission.READ_PHONE_STATE -> {
                title = App.instance().getString(R.string.permission_phone_status_data_collection)
            }
            App.instance().getString(R.string.permission_app_list_data_collection) -> {
                title = App.instance().getString(R.string.permission_app_list_data_collection)
            }
        }
        return title
    }

    fun getPermissionItem(permission: String): JSONObject{
        var item = JSONObject()
        item.put("permission",permission)
        item.put("isDeny",false)
        item.put("isMust",true)
        when(permission){
            Manifest.permission.READ_SMS -> {
                item.put("icon",R.mipmap.pic_permission_sms_icon)
                item.put("title",App.instance().getString(R.string.permission_sms_data_collection))
                item.put("msg",App.instance().getString(R.string.permission_sms_msg))
            }
            Manifest.permission.READ_CALL_LOG -> {
                item.put("icon",R.mipmap.pic_permission_call_icon)
                item.put("title",App.instance().getString(R.string.permission_call_log_collection))
            }
            Manifest.permission.READ_PHONE_STATE -> {
                item.put("icon",R.mipmap.pic_permission_phone_status_icon)
                item.put("title",App.instance().getString(R.string.permission_phone_status_data_collection))
                item.put("msg",App.instance().getString(R.string.permission_phone_status_msg))
            }
            App.instance().getString(R.string.permission_app_list_data_collection) -> {
                item.put("icon",R.mipmap.pic_permission_app_list_icon)
                item.put("title",App.instance().getString(R.string.permission_app_list_data_collection))
                item.put("msg",App.instance().getString(R.string.permission_app_list_msg))
                item.put("isAgree",false)
                item.put("isMust",false)
                item.put("isClick",false)//是否点击 拒绝 || 同意
            }
        }
        return item
    }
}